import { Component, Input, OnInit } from '@angular/core';
import { CommonService } from 'src/app/shared/service/common.service';

@Component({
  selector: 'app-left-nav',
  templateUrl: './left-nav.component.html',
  styleUrls: ['./left-nav.component.scss'],
})
export class LeftNavComponent implements OnInit {
  @Input() data: [];
  @Input() collapsed: boolean;

  @Input() level = 0;
  @Input() parent = [];

  constructor(private commonService: CommonService) {}

  ngOnInit(): void {
    // console.log(this.level);
  }

  titleClick(item, e) {
    // console.log(item);
    // console.log(this.parent)
    e.stopPropagation();
    console.log(item);

    if (item.items) {
      if (item.open == null) {
        item.open = false;
      }
      item.open = !item.open;
    } else {
      this.commonService.currentPath.next(this.parent.concat(item.label));
    }
  }

  newParent(item) {
    return this.parent.concat(item);
  }
}
